﻿<?php
require ("webfunc.php");

$origURL= '/home.do';
$globalsid = '';
if(array_key_exists('email',$_GET))
{
	$useremail = $_GET['email'];
	if($useremail == 'flamepjlh@126.com')
		$globalsid = $global_126;
	if($useremail == 'flamepjlh@163.com')
		$globalsid = $global_163;
	if($useremail == 'fxckgfw1@gmail.com')
		$globalsid = $global_gmail;
}
else
{
	$useremail = 'flamepjlh@126.com';
}
if(array_key_exists('pwd',$_GET))
{
	$userpwd = $_GET['pwd'];
}
else
{
	$userpwd = 'flamehjhj';
}
if(array_key_exists('helper',$_GET))
{
	$helper = $_GET['helper'];
}
else
{
	$helper = '';
}
$login = '登录';
$curlPost = 'origURL='  . urlencode($origURL) . '&email=' . urlencode($useremail) . '&password='. urlencode($userpwd). '&login='. urlencode($login);
//$data = vlogin('http://3g.renren.com/login.do?fx=0&autoLogin=true', $curlPost);
$loginurl = 'http://3g.renren.com/home.do?sid='.$globalsid;
$data = vget($loginurl);
$ret1 = strip_tags($data, "<a>");
$ret2 = substr($ret1, strpos($ret1, 'sid='));
$sid = substr($ret2, strpos($ret2, 'sid='),strpos($ret2, '&amp') - strpos($ret2, 'sid='));
$ret1 = substr($ret1, strpos($ret1, 'http://mapp.renren.com/apps.do?'));
$appurl = substr($ret1, strpos($ret1, 'http://mapp.renren.com/apps.do?'), strpos($ret1, '>应用<') - strpos($ret1, 'http')-1);
$data = vget('http://mapps.renren.com/rr_farm/farm/action/wap,indexAction.php?'.$sid);
//$data = vget($appurl);
//$ret1 = substr($data, strpos($data, 'http://mapp.renren.com/apphistory.do?appid=53429'));
//$appurl = substr($ret1, strpos($ret1, 'http'), strpos($ret1, 'htf=751') - strpos($ret1, 'http')+7);
//$data = vget($appurl);
$coloreig = '/rr_farm/farm/action/wap,indexAction.php?&svv=1';
$appmainurl = 'http://mapps.renren.com';
$cropeig = '/rr_farm/farm/action/wap,myCropAction';
$treeeig = '/rr_farm/farm/action/wap,myTreeAction';
$animaleig = '/rr_farm/farm/action/wap,myAnimalAction';
$machineeig = '/rr_farm/farm/action/wap,myMachineAction';
$friendeig = '/rr_farm/farm/action/wap,myFriendsListAction';
if (strpos($data, $coloreig))
{
	$ret1 = substr($data, strpos($data, $coloreig));
	$simpleurl = $appmainurl.substr($ret1, strpos($ret1, $coloreig), strpos($ret1, ">简版") - strpos($ret1, $coloreig) - 1);
	$data = vget($simpleurl);
}
$animalurl = $appmainurl.substr($data, strpos($data, $animaleig), strpos($data, ">【畜牧】") - strpos($data, $animaleig) - 1);
$machineurl = $appmainurl.substr($data, strpos($data, $machineeig), strpos($data, ">【机械】") - strpos($data, $machineeig) - 1);
$friendurl = $appmainurl.substr($data, strpos($data, $friendeig), strpos($data, ">【好友农场】") - strpos($data, $friendeig) - 1);
if ($helper == '')
{
	if (strpos($data, "【畜牧】★"))
	{
		$animaldata = vget($animalurl);
		$animaldata = strip_tags($animaldata, "<a>");
		$animalurl2 = $animalurl."&curpage=1";
		$animaldata2 = vget($animalurl2);
		$animaldata2 = strip_tags($animaldata2, "<a>");
		$animalfeedeig = '/rr_farm/farm/action/wap,feedAction';
		while (strpos($animaldata, '喂食'))
		{
			$animaldata = substr($animaldata, strpos($animaldata, $animalfeedeig));
			$feedanimalurl = $appmainurl.substr($animaldata, 0, strpos($animaldata, ' class=') - 1);
			$animaldata = substr($animaldata, strpos($animaldata, '食'));
			$feedanimalresult = vget($feedanimalurl);
			$feedanimalform = strip_tags($feedanimalresult, "<form>");
			preg_match('/action="([^"]*)"/', $feedanimalform, $matches);
			$feedposturl = $appmainurl.$matches[1];
			$feedanimalresult = strip_tags($feedanimalresult, "<input>");
			$feedPost = '';
			preg_match_all('/name="([^"]*)"/', $feedanimalresult, $namematches);
			preg_match_all('/value="([^"]*)"/', $feedanimalresult, $valuematches);
			for ($i=0; $i<count($namematches[1]); $i++)
			{
				$feedPost = $feedPost."&".$namematches[1][$i]."=".urlencode($valuematches[1][$i]);
			}
			$feedPost = substr($feedPost, 1);
			$feedanimalresult = vpost($feedposturl, $feedPost);
			echo($feedanimalresult);
		}
		while (strpos($animaldata2, '喂食'))
		{
			$animaldata2 = substr($animaldata2, strpos($animaldata2, $animalfeedeig));
			$feedanimalurl = $appmainurl.substr($animaldata2, 0, strpos($animaldata2, ' class=') - 1);
			$animaldata2 = substr($animaldata2, strpos($animaldata2, '食'));
			$feedanimalresult = vget($feedanimalurl);
			$feedanimalform = strip_tags($feedanimalresult, "<form>");
			preg_match('/action="([^"]*)"/', $feedanimalform, $matches);
			$feedposturl = $appmainurl.$matches[1];
			$feedanimalresult = strip_tags($feedanimalresult, "<input>");
			$feedPost = '';
			preg_match_all('/name="([^"]*)"/', $feedanimalresult, $namematches);
			preg_match_all('/value="([^"]*)"/', $feedanimalresult, $valuematches);
			for ($i=0; $i<count($namematches[1]); $i++)
			{
				$feedPost = $feedPost."&".$namematches[1][$i]."=".urlencode($valuematches[1][$i]);
			}
			$feedPost = substr($feedPost, 1);
			$feedanimalresult = vpost($feedposturl, $feedPost);
			echo($feedanimalresult);
		}
	}
	if (strpos($data, "【机械】★"))
	{
		$Machinedata = vget($machineurl);
		$Machinedata = strip_tags($Machinedata, "<a>");
		$Machineurl2 = $machineurl."&curpage=1";
		$Machinedata2 = vget($Machineurl2);
		$Machinedata2 = strip_tags($Machinedata2, "<a>");
		$Machinefeedeig = '/rr_farm/farm/action/wap,feedAction';
		while (strpos($Machinedata, '添加'))
		{
			$Machinedata = substr($Machinedata, strpos($Machinedata, $Machinefeedeig));
			$feedMachineurl = $appmainurl.substr($Machinedata, 0, strpos($Machinedata, '>添加') - 1);
			$Machinedata = substr($Machinedata, strpos($Machinedata, '加'));
			$feedMachineresult = vget($feedMachineurl);
			$feedMachineform = strip_tags($feedMachineresult, "<form>");
			preg_match('/action="([^"]*)"/', $feedMachineform, $matches);
			$feedposturl = $appmainurl.$matches[1];
			$feedMachineresult = strip_tags($feedMachineresult, "<input>");
			$feedPost = '';
			preg_match_all('/name="([^"]*)"/', $feedMachineresult, $namematches);
			preg_match_all('/value="([^"]*)"/', $feedMachineresult, $valuematches);
			for ($i=0; $i<count($namematches[1]); $i++)
			{
				$feedPost = $feedPost."&".$namematches[1][$i]."=".urlencode($valuematches[1][$i]);
			}
			$feedPost = substr($feedPost, 1);
			$feedMachineresult = vpost($feedposturl, $feedPost);
			echo($feedMachineresult);
		}
		while (strpos($Machinedata2, '添加'))
		{
			$Machinedata2 = substr($Machinedata2, strpos($Machinedata2, $Machinefeedeig));
			$feedMachineurl = $appmainurl.substr($Machinedata2, 0, strpos($Machinedata2, '>添加') - 1);
			$Machinedata2 = substr($Machinedata2, strpos($Machinedata2, '加'));
			$feedMachineresult = vget($feedMachineurl);
			$feedMachineform = strip_tags($feedMachineresult, "<form>");
			preg_match('/action="([^"]*)"/', $feedMachineform, $matches);
			$feedposturl = $appmainurl.$matches[1];
			$feedMachineresult = strip_tags($feedMachineresult, "<input>");
			$feedPost = '';
			preg_match_all('/name="([^"]*)"/', $feedMachineresult, $namematches);
			preg_match_all('/value="([^"]*)"/', $feedMachineresult, $valuematches);
			for ($i=0; $i<count($namematches[1]); $i++)
			{
				$feedPost = $feedPost."&".$namematches[1][$i]."=".urlencode($valuematches[1][$i]);
			}
			$feedPost = substr($feedPost, 1);
			$feedMachineresult = vpost($feedposturl, $feedPost);
			echo($feedMachineresult);
		}
	}
}
else
{
	$data = vget($friendurl);
	$helpereig = '/rr_farm/farm/action/wap,friendsFarmAction.php?fid='.$helper;
	$judgestr = substr($data, strpos($data, $helpereig));
	$judgestr = substr($judgestr, 0, strpos($judgestr, '<a href'));
	if (strpos($judgestr, "可采摘或可喂食"))
	{
		$helperurl = $appmainurl.substr($judgestr, 0, strpos($judgestr, ' class=') - 1);
		$helperdata = vget($helperurl);
		if (strpos($helperdata, "【畜牧】★"))
		{
			$helperanimaleig = '/rr_farm/farm/action/wap,friendAnimalAction';
			$helperanimalurl = $appmainurl.substr($helperdata, strpos($helperdata, $helperanimaleig), strpos($helperdata, ">【畜牧】") - strpos($helperdata, $helperanimaleig) - 1);
			$helperanimalurl2 = $helperanimalurl."&curpage=1";
			$helperanimaldata = vget($helperanimalurl);
			$helperanimaldata = strip_tags($helperanimaldata, "<a>");
			$helperanimaldata2 = vget($helperanimalurl2);
			$helperanimaldata2 = strip_tags($helperanimaldata2, "<a>");
			$helperanimalfeedeig = '/rr_farm/farm/action/wap,feedFriendAction';
			while (strpos($helperanimaldata, '喂食'))
			{
				$helperanimaldata = substr($helperanimaldata, strpos($helperanimaldata, $helperanimalfeedeig));
				$helperfeedanimalurl = $appmainurl.substr($helperanimaldata, 0, strpos($helperanimaldata, ' class=') - 1);
				$helperanimaldata = substr($helperanimaldata, strpos($helperanimaldata, '食'));
				$helperfeedanimalresult = vget($helperfeedanimalurl);
				$helperfeedanimalform = strip_tags($helperfeedanimalresult, "<form>");
				preg_match('/action="([^"]*)"/', $helperfeedanimalform, $matches);
				$helperfeedposturl = $appmainurl.$matches[1];
				$helperfeedanimalresult = strip_tags($helperfeedanimalresult, "<input>");
				$feedPost = '';
				preg_match_all('/name="([^"]*)"/', $helperfeedanimalresult, $namematches);
				preg_match_all('/value="([^"]*)"/', $helperfeedanimalresult, $valuematches);
				for ($i=0; $i<count($namematches[1]); $i++)
				{
					$feedPost = $feedPost."&".$namematches[1][$i]."=".urlencode($valuematches[1][$i]);
				}
				$feedPost = substr($feedPost, 1);
				$helperfeedanimalresult = vpost($helperfeedposturl, $feedPost);
				//echo($helperfeedanimalresult);
			}
			while (strpos($helperanimaldata2, '喂食'))
			{
				$helperanimaldata2 = substr($helperanimaldata2, strpos($helperanimaldata2, $helperanimalfeedeig));
				$helperfeedanimalurl = $appmainurl.substr($helperanimaldata2, 0, strpos($helperanimaldata2, ' class=') - 1);
				$helperanimaldata2 = substr($helperanimaldata2, strpos($helperanimaldata2, '食'));
				$helperfeedanimalresult = vget($helperfeedanimalurl);
				$helperfeedanimalform = strip_tags($helperfeedanimalresult, "<form>");
				preg_match('/action="([^"]*)"/', $helperfeedanimalform, $matches);
				$helperfeedposturl = $appmainurl.$matches[1];
				$helperfeedanimalresult = strip_tags($helperfeedanimalresult, "<input>");
				$feedPost = '';
				preg_match_all('/name="([^"]*)"/', $helperfeedanimalresult, $namematches);
				preg_match_all('/value="([^"]*)"/', $helperfeedanimalresult, $valuematches);
				for ($i=0; $i<count($namematches[1]); $i++)
				{
					$feedPost = $feedPost."&".$namematches[1][$i]."=".urlencode($valuematches[1][$i]);
				}
				$feedPost = substr($feedPost, 1);
				$helperfeedanimalresult = vpost($helperfeedposturl, $feedPost);
				//echo($helperfeedanimalresult);
			}
		}
		if (strpos($helperdata, "【机械】★"))
		{
			$helperMachineeig = '/rr_farm/farm/action/wap,friendMachineAction';
			$helperMachineurl = $appmainurl.substr($helperdata, strpos($helperdata, $helperMachineeig), strpos($helperdata, ">【机械】") - strpos($helperdata, $helperMachineeig) - 1);
			$helperMachineurl2 = $helperMachineurl."&curpage=1";
			$helperMachinedata = vget($helperMachineurl);
			$helperMachinedata = strip_tags($helperMachinedata, "<a>");
			$helperMachinedata2 = vget($helperMachineurl2);
			$helperMachinedata2 = strip_tags($helperMachinedata2, "<a>");
			$helperMachinefeedeig = '/rr_farm/farm/action/wap,feedFriendAction';
			while (strpos($helperMachinedata, '添加'))
			{
				$helperMachinedata = substr($helperMachinedata, strpos($helperMachinedata, $helperMachinefeedeig));
				$helperfeedMachineurl = $appmainurl.substr($helperMachinedata, 0, strpos($helperMachinedata, ' class=') - 1);
				$helperMachinedata = substr($helperMachinedata, strpos($helperMachinedata, '加'));
				$helperfeedMachineresult = vget($helperfeedMachineurl);
				$helperfeedMachineform = strip_tags($helperfeedMachineresult, "<form>");
				preg_match('/action="([^"]*)"/', $helperfeedMachineform, $matches);
				$helperfeedposturl = $appmainurl.$matches[1];
				$helperfeedMachineresult = strip_tags($helperfeedMachineresult, "<input>");
				$feedPost = '';
				preg_match_all('/name="([^"]*)"/', $helperfeedMachineresult, $namematches);
				preg_match_all('/value="([^"]*)"/', $helperfeedMachineresult, $valuematches);
				for ($i=0; $i<count($namematches[1]); $i++)
				{
					$feedPost = $feedPost."&".$namematches[1][$i]."=".urlencode($valuematches[1][$i]);
				}
				$feedPost = substr($feedPost, 1);
				$helperfeedMachineresult = vpost($helperfeedposturl, $feedPost);
				echo($helperfeedMachineresult);
			}
			while (strpos($helperMachinedata2, '添加'))
			{
				$helperMachinedata2 = substr($helperMachinedata2, strpos($helperMachinedata2, $helperMachinefeedeig));
				$helperfeedMachineurl = $appmainurl.substr($helperMachinedata2, 0, strpos($helperMachinedata2, ' class=') - 1);
				$helperMachinedata2 = substr($helperMachinedata2, strpos($helperMachinedata2, '加'));
				$helperfeedMachineresult = vget($helperfeedMachineurl);
				$helperfeedMachineform = strip_tags($helperfeedMachineresult, "<form>");
				preg_match('/action="([^"]*)"/', $helperfeedMachineform, $matches);
				$helperfeedposturl = $appmainurl.$matches[1];
				$helperfeedMachineresult = strip_tags($helperfeedMachineresult, "<input>");
				$feedPost = '';
				preg_match_all('/name="([^"]*)"/', $helperfeedMachineresult, $namematches);
				preg_match_all('/value="([^"]*)"/', $helperfeedMachineresult, $valuematches);
				for ($i=0; $i<count($namematches[1]); $i++)
				{
					$feedPost = $feedPost."&".$namematches[1][$i]."=".urlencode($valuematches[1][$i]);
				}
				$feedPost = substr($feedPost, 1);
				$helperfeedMachineresult = vpost($helperfeedposturl, $feedPost);
				echo($helperfeedMachineresult);
			}
		}
	}
}
delcookie($cookie_file);
?>